﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Messaging;
using System.Threading;
using System.Collections;
using Class1._1;

namespace program1._1
{
    class myremoteObject : MarshalByRefObject, ImyremoteObject
    {
        int myvalue;
        public myremoteObject()
        {
          Console.WriteLine("contructor cua myremoteObject duoc tao moi");
        }
        public void SetValue(int newval)
        {
        Console.WriteLine("ham SetValue cua myremoteObject, gia tri cu {0},gia tri moi la {1} ", myvalue, newval);
            Console.WriteLine("cho 5 giay");
            Thread.Sleep(5000);
            myvalue=newval;
            Console.WriteLine("Da dat gia tri moi");
        }
        public int GetValue()
        {
          Console.WriteLine("Goi ham GetValue, gia tri hien tai {0}", myvalue);
            return myvalue;
        }
        public String GetName()
        {
          Console.WriteLine("Goi GetName tu MyRemoteOject");
            Console.WriteLine("cho 5 giay");
            Thread.Sleep(5000);
            Console.WriteLine("GetName tra ve");
            return "ABCXYZAAAAAAAAAAAAA";
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Server started.......");
            HttpChannel chnl= new HttpChannel(1234);
            ChannelServices.RegisterChannel(chnl, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyRemoteObject), "MyRemoteObject.soap", WellKnownObjectMode.Singleton); ;
            Console.ReadLine();
            
        }
    }
}
